package com.daocao.yfb.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import com.daocao.yfb.R;
import com.daocao.yfb.api.Api;
import com.daocao.yfb.api.bean.NickNameBean;
import com.daocao.yfb.base.BaseActivity;
import com.daocao.yfb.util.Network;
import com.daocao.yfb.util.RxLifeUtil;
import com.daocao.yfb.util.ToastUtil;
import com.daocao.yfb.util.UI;
import com.daocao.yfb.view.V19FrameLayout;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class ChangeNickNameActivity extends BaseActivity {
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.edit_phone)
    EditText editPhone;

    private Unbinder unbiner;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_change_nickname);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        txtTitle.setText("修改昵称");

    }

    public void getNickName(String nickname) {
        if (!Network.checkNetwork(this)) {
            ToastUtil.show(this, "网络连接失败");
            return;
        }
        NickNameBean bean = new NickNameBean();
        bean.nickname = nickname;
        Api.api_service.getNickName(bean).compose(RxLifeUtil.checkOn(this)).
                doFinally(() -> {
                    try {

                    } catch (NullPointerException e) {

                    }
                }).
                subscribe(result -> {
                    ToastUtil.makeText(this, "修改成功");
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @OnClick({R.id.btn_back, R.id.btn_submit})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_back:
                finish();
                break;
            case R.id.btn_submit:
                if (TextUtils.isEmpty(UI.toString(editPhone))) {
                    ToastUtil.makeText(this, "昵称不能为空");
                    return;
                }
                getNickName(UI.toString(editPhone));
                break;
        }
    }
}
